/**
 * Created by root on 2017/8/14.
 * 新建笔记
 */
window.onload=function(){
    var mytitle=document.getElementById("mytitle");
    var mytext=document.getElementById("mytext");
    var save_button=document.getElementById("save_button");
    var return_button=document.getElementById("return_button");
    save_button.onclick=function(){
        var xmlhttp=new XMLHttpRequest();
        xmlhttp.open("POST","i/note/note/add_note",true);           //保存新建笔记
        xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
        var message_send="title="+mytitle.value+"&text="+mytext.value;
        xmlhttp.onreadystatechange=function(){
            if(xmlhttp.readyState==4)
            {
                if(xmlhttp.status==200)
                {
                    var data=JSON.parse(xmlhttp.responseText);
                    if(data.result==1)
                    {
                        alert("保存成功！");
                        window.location.href="Main.html";
                    }
                }
            }
            else{
                alert("保存失败!");
            }
        }
        xmlhttp.send(message_send);
    }

    return_button.onclick=function(){
        window.location.href="Main.html";
    }
}